﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Buy2Site.Classes;
using System.IO;

namespace Buy2Site.UserControls
{
    public partial class ProductControl : System.Web.UI.UserControl
    {
        public long ProductID { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                
                linkAddToCart.Enabled = false;
                
            }
            else
            {
                linkAddToCart.Enabled = true;
            }
        }

        public string Title 
        {
            get
            {
                return lblProductName.Text;
            }
            set
            {
                lblProductName.Text = value;
            }
        }
        public decimal Price 
        {
            get
            {
                return Convert.ToDecimal(lblPrice.Text);
            }
            set
            {
                lblPrice.Text = Convert.ToString(value);
            }
        }
        public DateTime Date 
        {
            get
            {
                return Convert.ToDateTime(lblDate.Text);
            }
            set
            {
                lblDate.Text = Convert.ToDateTime(value).ToString();
            }
        }
        public string ShortDescription 
        {
            get
            {
                return lblShortDescrption.Text;
            }
            set
            {
                lblShortDescrption.Text = value;
            }
        }
        //public string LongDescription
        //{
        //    get
        //    {
        //        return lblLongDescrption.Text;
        //    }
        //    set
        //    {
        //        lblLongDescrption.Text = value;
        //    }
        //}
        public string Image1 
        {
            get
            {
                return Picture1.ImageUrl;
            }
            set
            {
                Picture1.ImageUrl = value;
            }
        }
        //public string Image2
        //{
        //    get
        //    {
        //        return Picture2.ImageUrl;
        //    }
        //    set
        //    {
        //        Picture2.ImageUrl = value;
        //    }
        //}
        //public string Image3
        //{
        //    get
        //    {
        //        return Picture3.ImageUrl;
        //    }
        //    set
        //    {
        //        Picture3.ImageUrl = value;
        //    }
        //}

        //protected void ActivateAddToCartEvent(object sender, EventArgs e)
        //{
        //    // TODO
        //    // add to ListOfItems list - for session per user
        //    ((ProductClass)Session["ListOfItems"]).ListOfItems.Add(
        //        new ProductClass()
        //        {
        //            Title = this.Title,
        //            Price = Convert.ToDouble(this.Price),
        //            Date = this.Date,
        //            ShortDescription = this.ShortDescription,
        //            //LongDescription = this.LongDescription,
        //            Picture1 = File.ReadAllBytes(this.Image1),
        //            //Picture2 = File.ReadAllBytes(this.Image2),
        //            //Picture3 = File.ReadAllBytes(this.Image3)
        //        });
        //    // add to ListOfAllQuantetiesItems list - for Application - to manage product quanteties
        //    ((ProductClass)Application["ListOfAllQuantetiesItems"]).ListOfAllQuantetiesItems.Add(
        //        new ProductClass()
        //        {
        //            Title = this.Title,
        //            Price = Convert.ToDouble(this.Price),
        //            Date = this.Date,
        //            ShortDescription = this.ShortDescription,
        //            //LongDescription = this.LongDescription,
        //            Picture1 = File.ReadAllBytes(this.Image1),
        //            //Picture2 = File.ReadAllBytes(this.Image2),
        //            //Picture3 = File.ReadAllBytes(this.Image3)
        //        });
        //    //CartItemsManager.AddToCartList(new ProductClass()
        //    //{ 
        //    //    Title=this.Title,
        //    //    Price= Convert.ToDouble(this.Price),
        //    //    Date=this.Date,
        //    //    ShortDescription=this.ShortDescription,
        //    //    LongDescription=this.LongDescription,
        //    //    Picture1=File.ReadAllBytes(this.Image1),
        //    //    Picture2=File.ReadAllBytes(this.Image2),
        //    //    Picture3=File.ReadAllBytes(this.Image3)
        //    //});            
        //}

        //protected void ActivateMoreDetailsEvent(object sender, EventArgs e)
        //{
        //    Response.Redirect("~/Pages/ProductDetailsPage.aspx");
        //}

        //protected void ActivateAddToCartEvent(object sender, ImageClickEventArgs e)
        //{
        //    // TODO
        //    // add to ListOfItems list - for session per user
        //    ((ProductClass)Session["ListOfItems"]).ListOfItems.Add(
        //        new ProductClass()
        //        {
        //            Title = this.Title,
        //            Price = Convert.ToDouble(this.Price),
        //            Date = this.Date,
        //            ShortDescription = this.ShortDescription,
        //            //LongDescription = this.LongDescription,
        //            Picture1 = File.ReadAllBytes(this.Image1),
        //            //Picture2 = File.ReadAllBytes(this.Image2),
        //            //Picture3 = File.ReadAllBytes(this.Image3)
        //        });
        //    // add to ListOfAllQuantetiesItems list - for Application - to manage product quanteties
        //    ((ProductClass)Application["ListOfAllQuantetiesItems"]).ListOfAllQuantetiesItems.Add(
        //        new ProductClass()
        //        {
        //            Title = this.Title,
        //            Price = Convert.ToDouble(this.Price),
        //            Date = this.Date,
        //            ShortDescription = this.ShortDescription,
        //            //LongDescription = this.LongDescription,
        //            Picture1 = File.ReadAllBytes(this.Image1),
        //            //Picture2 = File.ReadAllBytes(this.Image2),
        //            //Picture3 = File.ReadAllBytes(this.Image3)
        //        });
        //    //CartItemsManager.AddToCartList(new ProductClass()
        //    //{ 
        //    //    Title=this.Title,
        //    //    Price= Convert.ToDouble(this.Price),
        //    //    Date=this.Date,
        //    //    ShortDescription=this.ShortDescription,
        //    //    LongDescription=this.LongDescription,
        //    //    Picture1=File.ReadAllBytes(this.Image1),
        //    //    Picture2=File.ReadAllBytes(this.Image2),
        //    //    Picture3=File.ReadAllBytes(this.Image3)
        //    //});   
        //}

        //protected void ActivateMoreDetailsEvent(object sender, ImageClickEventArgs e)
        //{
            
        //    Response.Redirect("~/Pages/ProductDetailsPage.aspx");
        //}

        protected void btnMoreDetailsLink_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "MoreDetails")
            {
                Response.Redirect("~/Pages/ProductDetailsPage.aspx?productID=" + ProductID);
            }
        }

        //protected void btnAddToCartLink_Command(object sender, CommandEventArgs e)
        //{
        //    if (e.CommandName == "AddToCart")
        //    {
        //        // TODO
        //        // add to ListOfItems list - for session per user
        //        ((ProductClass)Session["ListOfItems"]).ListOfItems.Add(
        //            new ProductClass()
        //            {
        //                Title = this.Title,
        //                Price = Convert.ToDouble(this.Price),
        //                Date = this.Date,
        //                ShortDescription = this.ShortDescription,
        //                //LongDescription = this.LongDescription,
        //                Picture1 = File.ReadAllBytes(this.Image1),
        //                //Picture2 = File.ReadAllBytes(this.Image2),
        //                //Picture3 = File.ReadAllBytes(this.Image3)
        //            });
        //        // add to ListOfAllQuantetiesItems list - for Application - to manage product quanteties
        //        ((ProductClass)Application["ListOfAllQuantetiesItems"]).ListOfAllQuantetiesItems.Add(
        //            new ProductClass()
        //            {
        //                Title = this.Title,
        //                Price = Convert.ToDouble(this.Price),
        //                Date = this.Date,
        //                ShortDescription = this.ShortDescription,
        //                //LongDescription = this.LongDescription,
        //                Picture1 = File.ReadAllBytes(this.Image1),
        //                //Picture2 = File.ReadAllBytes(this.Image2),
        //                //Picture3 = File.ReadAllBytes(this.Image3)
        //            });
        //    }
        //}

        //protected void btnAddToCart_Command(object sender, CommandEventArgs e)
        //{                        
        //    if (e.CommandName == "AddToCart")
        //    {
        //        // TODO
        //        // add to ListOfItems list - for session per user
        //        ((ProductClass)Session["ListOfItems"]).ListOfItems.Add(
        //            new ProductClass()
        //            {
        //                Title = this.Title,
        //                Price = Convert.ToDouble(this.Price),
        //                Date = this.Date,
        //                ShortDescription = this.ShortDescription,
        //                //LongDescription = this.LongDescription,
        //                Picture1 = File.ReadAllBytes(this.Image1),
        //                //Picture2 = File.ReadAllBytes(this.Image2),
        //                //Picture3 = File.ReadAllBytes(this.Image3)
        //            });
        //        // add to ListOfAllQuantetiesItems list - for Application - to manage product quanteties
        //        ((ProductClass)Application["ListOfAllQuantetiesItems"]).ListOfAllQuantetiesItems.Add(
        //            new ProductClass()
        //            {
        //                Title = this.Title,
        //                Price = Convert.ToDouble(this.Price),
        //                Date = this.Date,
        //                ShortDescription = this.ShortDescription,
        //                //LongDescription = this.LongDescription,
        //                Picture1 = File.ReadAllBytes(this.Image1),
        //                //Picture2 = File.ReadAllBytes(this.Image2),
        //                //Picture3 = File.ReadAllBytes(this.Image3)
        //            });
        //    }
        //}

        protected void btnAddToCart_Command(object sender, EventArgs e)
        {
            
            // TODO
            // add to ListOfItems list - for session per user
            ((ProductClass)Session["ListOfItems"]).ListOfItems.Add(
                new ProductClass()
                {
                    Title = this.Title,
                    Price = Convert.ToDouble(this.Price),
                    Date = this.Date,
                    ShortDescription = this.ShortDescription,
                    //LongDescription = this.LongDescription,
                    Picture1 = File.ReadAllBytes(this.Image1),
                    //Picture2 = File.ReadAllBytes(this.Image2),
                    //Picture3 = File.ReadAllBytes(this.Image3)
                });
            // add to ListOfAllQuantetiesItems list - for Application - to manage product quanteties
            ((ProductClass)Application["ListOfAllQuantetiesItems"]).ListOfAllQuantetiesItems.Add(
                new ProductClass()
                {
                    Title = this.Title,
                    Price = Convert.ToDouble(this.Price),
                    Date = this.Date,
                    ShortDescription = this.ShortDescription,
                    //LongDescription = this.LongDescription,
                    Picture1 = File.ReadAllBytes(this.Image1),
                    //Picture2 = File.ReadAllBytes(this.Image2),
                    //Picture3 = File.ReadAllBytes(this.Image3)
                });
            
        }        
    }
}